
$(document).ready(function() {
    $("#register").on("click", function() {
        window.location.href = "../web/register.html";
    });
    $(function () {
        $("#login").click(function () {
            let userId = $("#login-username").val();
            let userPwd = $("#login-password").val();
            var code = $('input[name="code"]').val();
            //认证中..
            $('.login').addClass('test'); //倾斜特效
            setTimeout(function () {
                $('.login').addClass('testtwo'); //平移特效
            }, 300);
            setTimeout(function () {
                $('.authent').show().animate({ right: -320 }, {
                    easing: 'easeOutQuint',
                    duration: 600,
                    queue: false
                });
                $('.authent').animate({ opacity: 1 }, {
                    duration: 200,
                    queue: false
                }).addClass('visible');
            }, 500);

                $.ajax({
                    url: '/user/login',
                    type: 'get',
                    dataType: 'json',
                    async:false,
                    data:{"userId":userId,"userPwd":userPwd.toString()},
                    success: function (data) {
                            let userName = data.userName;
                            localStorage.setItem('userId',userId);
                            localStorage.setItem('state','0');
                            localStorage.setItem('userName',userName);


                            $.ajax({
                                url:'/msg/insertUserLogin',
                                type:'post',
                                dataType: 'json',
                                data:{"userId":userId,"userName":userName,"userLoginTime": new Date().toString()},
                                success: function (data1){
                                    console.log(data1);
                                    console.log("成功");
                                }
                            });
                        // Continue the animation on success
                        setTimeout(function () {
                            $('.authent').show().animate({ right: 90 }, {
                                easing: 'easeOutQuint',
                                duration: 600,
                                queue: false
                            });
                            $('.authent').animate({ opacity: 0 }, {
                                duration: 200,
                                queue: false
                            }).addClass('visible');
                            $('.login').removeClass('testtwo'); // Remove translate effect
                        }, 2000);
                        setTimeout(function () {
                            $('.authent').hide();
                            $('.login').removeClass('test');
                            // Login successful
                            $('.login div').fadeOut(100);
                            $('.success').fadeIn(1000);
                            $('.success').html("登陆成功<br /><br />欢迎回来");
                            // Set another timeout to ensure the message is displayed before redirecting
                            setTimeout(function () {
                                window.location.href = "../web/loading.html";
                            }, 2400); // This delay should be enough to show the success message
                        }, 2400);

                    },
                    error:function (){
                        $('.error').html( "账号名或密码或验证码有误");
                    }
                });
        })


    });

})
function jump(){
    window.location.href=("../index.html?userId="+localStorage.getItem("userId")+"&" +encodeURI(localStorage.getItem("userName")));
}